package com.cattsoft.convert;

import java.util.Map;

import com.cattsoft.model.Point;

import ognl.DefaultTypeConverter;

public class PointConvertor extends DefaultTypeConverter {

	@Override
	public Object convertValue(Map context, Object value, Class toType) {
		if (toType == Point.class) {
			String[] strs = (String[]) value;
			String[] params = strs[0].split(",");

			int x = Integer.parseInt(params[0]);
			int y = Integer.parseInt(params[1]);

			Point point = new Point();
			point.setX(x);
			point.setY(y);

			return point;
		} else {
			Point p = (Point) value;
			return " x= " + p.getX() + ",y=" + p.getY();
		}
	}
	
}
